/*
 * @lc app=leetcode.cn id=1700 lang=typescript
 *
 * [1700] 无法吃午餐的学生数量
 */

// @lc code=start
function countStudents(students: number[], sandwiches: number[]): number {
    let num1 = students.reduce((a, b) => (b === 1 ? a + 1 : a), 0);
    let num0 = students.length - num1;
    while (true) {
        if (sandwiches[0] === 0 && num0) {
            num0--;
            sandwiches.shift();
        } else if (sandwiches[0] === 1 && num1) {
            num1--;
            sandwiches.shift();
        } else {
            return num0 + num1;
        }
    }
}
// @lc code=end
